<?php
namespace app\admin2\controller;

use app\common\model\KwReply as KwReplyModel;
use app\common\controller\AdminBaseo;

class KwReply extends AdminBaseo
{
    protected $kw_reply_model;

    public function _initialize(){
        parent::_initialize();
        $this->kw_reply_model = new KwReplyModel;
    }

    public function getKwReplyList(){
        $kw_reply_list = $this->kw_reply_model->showList();
        return json(['status' => 1 , 'msg' => 'ok' , 'kw_reply_list' => $kw_reply_list]);
    }

    public function add(){
        return $this->fetch();
    }

    public function kw_save(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $result = $this->kw_reply_model->allowField(true)->save($data);
            if($result){
                return json(['status' => 1 , 'msg' => 'ok']);
            }else{
                return json(['status' => -1 , 'error' => 'error']);
            }
        }
    }

    public function kw_update($id){
        if($this->request->isPost()){
            $data = $this->request->post();

            $result = $this->kw_reply_model->allowField(true)->save($data,['id' => $id]);
            if($result){
                return json(['status' => 1 , 'msg' => 'ok']);
            }else{
                return json(['status' => -1 , 'error' => 'error']);
            }
        }
    }

    public function kw_delete($id){
        $result = $this->kw_reply_model->destroy($id);
        if($result){
            return json(['status' => 1 , 'msg' => 'ok']);
        }else{
            return json(['status' => -1 , 'error' => 'error']);
        }
    }

    /**
     * 关键词回复详情
     */
    public function kw_detail($id){
        $kw_reply_info = $this->kw_reply_model->showOne($id);

        if($kw_reply_info){
            return json(['status' => 1 , 'msg' => 'ok' , 'kw_reply_info' => $kw_reply_info]);
        }else{
            return json(['status' => -1 , 'error' => 'error']);
        }
    }
}